
#include <stdio.h>
#include <string.h>

#include <vector>
#include <string>

#include "nmapconfig.hpp"

#define	INI_FILENAME "nmap.conf"
#define	INI_SECTION	 "fish"


int	main ( void )
{
	{
		fprintf(stderr, "\ntest section [%s] in %s ...\n", INI_SECTION, INI_FILENAME );
		NMapConfig	nmc( INI_FILENAME, INI_SECTION );
		fprintf(stderr, "NMap Bound [ %d .. %d ]\n", nmc.lowbound(), nmc.upbound() );

		NMapConfig::target_list_ptr_type	targets_p = NULL;

		int	id;

		int	invalid_ids[] = { -1, 65537, 0 };
		for ( int idx=0; invalid_ids[idx] != 0; ++idx ) {
			id = invalid_ids[ idx ];
			targets_p = nmc.lookup( id );
			if ( NULL != targets_p ) {
				fprintf( stderr, "ID=%d ASSERT : targets_p == NULL\n", id );
				return	1;
			}
		}


		int	valid_ids[] = { 0, 1, 65536, -1 };
		for (int idx = 0; valid_ids[idx] >= 0; ++idx ) {
			id = valid_ids[ idx ];
			targets_p = nmc.lookup( id );
			if ( NULL == targets_p ) {
				fprintf( stderr, "ID=%d ASSERT : targets_p != NULL\n", id );
				return	2;
			}
			fprintf(stderr, "ID=%d targets count=%lu\n", id, targets_p->size() );
			for ( unsigned i=0; i<targets_p->size(); ++i ) {
				const std::string*	p = targets_p->at(i);
				fprintf( stderr, "    ID=%d #%u --> %s\n", id, i, p->c_str() );
			}
		}
	}
	
	{
		fprintf(stderr, "\ntest all section in %s ...\n", INI_FILENAME );
		// ignore INI section
		NMapConfig	nmc( INI_FILENAME, NULL );
		fprintf(stderr, "NMap Bound [ %d .. %d ]\n", nmc.lowbound(), nmc.upbound() );

		NMapConfig::target_list_ptr_type	targets_p = NULL;

		int	id;

		int	invalid_ids[] = { -1, 65537, 0 };
		for ( int idx=0; invalid_ids[idx] != 0; ++idx ) {
			id = invalid_ids[ idx ];
			targets_p = nmc.lookup( id );
			if ( NULL != targets_p ) {
				fprintf( stderr, "ID=%d ASSERT : targets_p == NULL\n", id );
				return	1;
			}
		}

		int	valid_ids[] = { 0, 1, 65536, -1 };
		for (int idx = 0; valid_ids[idx] >= 0; ++idx ) {
			id = valid_ids[ idx ];
			targets_p = nmc.lookup( id );
			if ( NULL == targets_p ) {
				fprintf( stderr, "ID=%d ASSERT : targets_p != NULL\n", id );
				return	2;
			}
			fprintf(stderr, "ID=%d targets count=%lu\n", id, targets_p->size() );
			for ( unsigned i=0; i<targets_p->size(); ++i ) {
				const std::string*	p = targets_p->at(i);
				fprintf( stderr, "    ID=%d #%u --> %s\n", id, i, p->c_str() );
			}
		}
	}
	
	return	0;
}

